package com.example.park2212.points

import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.entity.PointsBeanItem
import com.example.lib_base.entity.PointsBeanItemItem
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.databinding.ActivityPointsAddBinding
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.internal.notify
import okhttp3.internal.notifyAll

@AndroidEntryPoint
@Route(path = "/app/points/PointsAddActivity")
class PointsAddActivity : BaseActivity<ActivityPointsAddBinding,PointsViewModel>() {
    var type = ""
    override fun initView() {
        binding.pointsAdd.headerTitle.setText("点位管理")
        binding.pointsAdd.headerBack.setOnClickListener {
            finish()
        }




        val list = mutableListOf<String>("安防巡检","保洁巡检","日常巡检","家居巡检")
        val adapter = ArrayAdapter(this,android.R.layout.simple_spinner_item,list)
        binding.pointsSptype.adapter = adapter
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        binding.pointsSptype.onItemSelectedListener = object :OnItemSelectedListener{
            override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
                type = list[p2]
            }

            override fun onNothingSelected(p0: AdapterView<*>?) {

            }
        }


        binding.btnTj.setOnClickListener {
            val etaddress = binding.pointsAddetaddress.text.toString()
            val etName = binding.pointsAddetname.text.toString()
            val etprovider = binding.pointsAddetprovider.text.toString()
            val etBz = binding.pointsAddetbz.text.toString()
            val beanItem =
                PointsBeanItemItem(0, etBz, type, listOf("http://images.com/1.png,http://images.com/2.png,http://images.com/3.png").toString(), etaddress, etName, etprovider)
            viewModel.addPoints(beanItem)
            //刷新
            viewModel.points()
        }

    }

    override fun initData() {
        viewModel.addPointSuccess.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

}